package com.example.demo.event.spring;

import com.example.demo.bean.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

/**
 * 监听器
 * @author lyc
 * @date 2019/6/10.
 */
@Component
@Slf4j
public class UserRegisterListener implements ApplicationListener {
    @Override
    public void onApplicationEvent(ApplicationEvent applicationEvent) {
        //触发事件 这里是同步的 异步处理 考虑线程池
        if(applicationEvent instanceof UserRegisterEvent) {
            log.info("事件触发");
            UserRegisterEvent userRegisterEvent = (UserRegisterEvent) applicationEvent;
            User user = (User) userRegisterEvent.getSource();
            log.info("原数据{}", user);
           //throw new FieldException("================================");
        }
    }
}